package com.jss.lanouhn.fristapp.adapters;

import android.app.Activity;
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.jss.lanouhn.fristapp.R;
import com.jss.lanouhn.fristapp.modles.FreeFragmentRightInfo;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by lanouhn on 16/9/3.
 */
public class FreeRightBottomRvAdapter extends RecyclerView.Adapter<FreeRightBottomRvAdapter.BottomRvViewHolder>{
    private Context context;
    private List<FreeFragmentRightInfo.DataBean.RecordsBean.AwardUsersBean> beans;
    DisplayMetrics dm;

    public FreeRightBottomRvAdapter(Context context, List<FreeFragmentRightInfo.DataBean.RecordsBean.AwardUsersBean> beans) {
        this.context = context;
        this.beans = beans;
        dm = new DisplayMetrics();
        ((Activity)context).getWindowManager().getDefaultDisplay().getMetrics(dm);
    }

    @Override
    public BottomRvViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view= LayoutInflater.from(context).inflate(R.layout.item_free_item_bottom_rv,null);
        RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams((dm.widthPixels - dip2px(20)), (dm.widthPixels - dip2px(20))/5);
        view.setLayoutParams(lp);
        BottomRvViewHolder holder=new BottomRvViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(BottomRvViewHolder holder, int position) {
        holder.tv_name.setText(beans.get(position).getNickname());
        holder.tv_content.setText(beans.get(position).getAward_word());
        Picasso.with(context).load(beans.get(position).getAvatar_url()).into(holder.imageView);
    }

    @Override
    public int getItemCount() {
        return beans.size();
    }

    public class BottomRvViewHolder extends RecyclerView.ViewHolder {
        private ImageView imageView;
        private TextView tv_name,tv_content,tv_time;
        public BottomRvViewHolder(View itemView) {
            super(itemView);
            imageView= (ImageView) itemView.findViewById(R.id.circle_free_item_icon);
            tv_name= (TextView) itemView.findViewById(R.id.tv_item_free_name);
            tv_content= (TextView) itemView.findViewById(R.id.tv_item_free_content);
            tv_time= (TextView) itemView.findViewById(R.id.tv_item_free_time_bottom);

        }
    }
    int dip2px(float dpValue) {
        final float scale = context.getResources().getDisplayMetrics().density;
        return (int) (dpValue * scale + 0.5f);
    }
}
